//
//  ZFBNewNoteViewController.m
//  支付宝
//
//  Created by GD on 16/8/6.
//  Copyright © 2016年 HM. All rights reserved.
//   view给控制器的传值,可以使用add-Action模式.   但是控制器之间的传值,只能用代理,通知,或者Block.

#import "ZFBNewNoteViewController.h"

@interface ZFBNewNoteViewController ()

@property (nonatomic,weak) UITextView *txtView;

@end

@implementation ZFBNewNoteViewController

NSString *const  kZFBNoteDateKey = @"kZFBNoteDateKey";

NSString *const kZFBNoteContentKey = @"kZFBNoteContentKey";


#pragma mark - event (selctor --btn,notification,itemBtn)
-(void)clickCancel
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadViewNotification" object:nil userInfo:nil];//为什么要发送通知?
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)clickSave
{
    //    NoteBL *bl = [[NoteBL alloc] init];
    //    Note *note = [[Note alloc] init];
    //    note.date = [Tool getLocalDateStr];
    //    note.content = self.txtView.text;
    //    NSMutableArray *reslist = [bl createNote:note];
    
    //    [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadViewNotification" object:reslist userInfo:nil];
    //    [self.txtView resignFirstResponder];
//    ZFBNoteModel *noteModel = [[ZFBNoteModel alloc] init];
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
//    //    dict[kZFBNoteDateKey = [NSDate date].description;
//    //    noteModel.kZFBNoteContentKey = _txtView.text;
    [dict setValue:[NSDate date].description forKey:kZFBNoteDateKey];
    [dict setValue:_txtView.text forKey:kZFBNoteContentKey];//感觉setValue:forKey:是KVC的方法.
    [self.delegate newNoteController:self didFinishAddNote:dict];

    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self setupUI];
}

-(void)setupUI
{
    UITextView *txtView = [[UITextView alloc] initWithFrame:self.view.bounds];
    txtView.font = [UIFont systemFontOfSize:15];
    [self.view addSubview:txtView];
    self.txtView = txtView;
    
    //设置右上角按钮
    UIBarButtonItem *save = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(clickSave)];
    self.navigationItem.rightBarButtonItem = save;
    //设置左上角按钮
    UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(clickCancel)];
    self.navigationItem.leftBarButtonItem = cancel;
    
    self.title = @"新建note";
    self.view.backgroundColor = [UIColor whiteColor];
}

@end
